/**
 */
package spem.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import spem.SPEMDiagram;
import spem.SemanticElement;
import spem.SpemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Semantic Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link spem.impl.SemanticElementImpl#getChildrent <em>Childrent</em>}</li>
 *   <li>{@link spem.impl.SemanticElementImpl#getParent <em>Parent</em>}</li>
 *   <li>{@link spem.impl.SemanticElementImpl#getDiagram <em>Diagram</em>}</li>
 *   <li>{@link spem.impl.SemanticElementImpl#getName <em>Name</em>}</li>
 *   <li>{@link spem.impl.SemanticElementImpl#getLayout <em>Layout</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class SemanticElementImpl extends EObjectImpl implements SemanticElement {
	/**
	 * The cached value of the '{@link #getChildrent() <em>Childrent</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChildrent()
	 * @generated
	 * @ordered
	 */
	protected EList<SemanticElement> childrent;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getLayout() <em>Layout</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLayout()
	 * @generated
	 * @ordered
	 */
	protected Object layout;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected SemanticElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SpemPackage.Literals.SEMANTIC_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<SemanticElement> getChildrent() {
		if (childrent == null) {
			childrent = new EObjectContainmentWithInverseEList<SemanticElement>(SemanticElement.class, this, SpemPackage.SEMANTIC_ELEMENT__CHILDRENT, SpemPackage.SEMANTIC_ELEMENT__PARENT);
		}
		return childrent;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SemanticElement getParent() {
		if (eContainerFeatureID() != SpemPackage.SEMANTIC_ELEMENT__PARENT) return null;
		return (SemanticElement)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetParent(SemanticElement newParent, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newParent, SpemPackage.SEMANTIC_ELEMENT__PARENT, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParent(SemanticElement newParent) {
		if (newParent != eInternalContainer() || (eContainerFeatureID() != SpemPackage.SEMANTIC_ELEMENT__PARENT && newParent != null)) {
			if (EcoreUtil.isAncestor(this, newParent))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newParent != null)
				msgs = ((InternalEObject)newParent).eInverseAdd(this, SpemPackage.SEMANTIC_ELEMENT__CHILDRENT, SemanticElement.class, msgs);
			msgs = basicSetParent(newParent, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SpemPackage.SEMANTIC_ELEMENT__PARENT, newParent, newParent));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public SPEMDiagram getDiagram() {
		if (eContainerFeatureID() != SpemPackage.SEMANTIC_ELEMENT__DIAGRAM) return null;
		return (SPEMDiagram)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetDiagram(SPEMDiagram newDiagram, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newDiagram, SpemPackage.SEMANTIC_ELEMENT__DIAGRAM, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDiagram(SPEMDiagram newDiagram) {
		if (newDiagram != eInternalContainer() || (eContainerFeatureID() != SpemPackage.SEMANTIC_ELEMENT__DIAGRAM && newDiagram != null)) {
			if (EcoreUtil.isAncestor(this, newDiagram))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newDiagram != null)
				msgs = ((InternalEObject)newDiagram).eInverseAdd(this, SpemPackage.SPEM_DIAGRAM__ELEMENT, SPEMDiagram.class, msgs);
			msgs = basicSetDiagram(newDiagram, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SpemPackage.SEMANTIC_ELEMENT__DIAGRAM, newDiagram, newDiagram));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SpemPackage.SEMANTIC_ELEMENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object getLayout() 
	{
		/*
		if (layout != null) {
			InternalEObject oldLayout = (InternalEObject)layout;
			layout = eResolveProxy(oldLayout);
			if (layout != oldLayout) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SpemPackage.SEMANTIC_ELEMENT__LAYOUT, oldLayout, layout));
			}
		}
		*/
		return layout;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Object basicGetLayout() {
		return layout;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLayout(Object newLayout) {
		Object oldLayout = layout;
		layout = newLayout;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SpemPackage.SEMANTIC_ELEMENT__LAYOUT, oldLayout, layout));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getChildrent()).basicAdd(otherEnd, msgs);
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetParent((SemanticElement)otherEnd, msgs);
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetDiagram((SPEMDiagram)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				return ((InternalEList<?>)getChildrent()).basicRemove(otherEnd, msgs);
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				return basicSetParent(null, msgs);
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				return basicSetDiagram(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID()) {
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				return eInternalContainer().eInverseRemove(this, SpemPackage.SEMANTIC_ELEMENT__CHILDRENT, SemanticElement.class, msgs);
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				return eInternalContainer().eInverseRemove(this, SpemPackage.SPEM_DIAGRAM__ELEMENT, SPEMDiagram.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				return getChildrent();
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				return getParent();
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				return getDiagram();
			case SpemPackage.SEMANTIC_ELEMENT__NAME:
				return getName();
			case SpemPackage.SEMANTIC_ELEMENT__LAYOUT:
				if (resolve) return getLayout();
				return basicGetLayout();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				getChildrent().clear();
				getChildrent().addAll((Collection<? extends SemanticElement>)newValue);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				setParent((SemanticElement)newValue);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				setDiagram((SPEMDiagram)newValue);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__NAME:
				setName((String)newValue);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__LAYOUT:
				setLayout((EObject)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				getChildrent().clear();
				return;
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				setParent((SemanticElement)null);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				setDiagram((SPEMDiagram)null);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case SpemPackage.SEMANTIC_ELEMENT__LAYOUT:
				setLayout((EObject)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SpemPackage.SEMANTIC_ELEMENT__CHILDRENT:
				return childrent != null && !childrent.isEmpty();
			case SpemPackage.SEMANTIC_ELEMENT__PARENT:
				return getParent() != null;
			case SpemPackage.SEMANTIC_ELEMENT__DIAGRAM:
				return getDiagram() != null;
			case SpemPackage.SEMANTIC_ELEMENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case SpemPackage.SEMANTIC_ELEMENT__LAYOUT:
				return layout != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //SemanticElementImpl
